'use strict';

module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
  const User = app.model.define('user', {
    userName: {
      type: STRING,
      unique: true,
      allowNull: false,
      comment: '用户名，唯一，不能为空',
    },
    password: {
      type: STRING,
      allowNull: false,
      comment: '密码',
    },
    nickName: {
      type: STRING,
      comment: '昵称',
    },
    gender: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '性别（1男，2女，3保密）',
    },
    avatar: {
      type: STRING,
      comment: '头像，图片路径',
    },
    city: {
      type: STRING,
      allowNull: false,
      defaultValue: '秦皇岛',
      comment: '城市',
    },
  });

  // 创建连接关系
  User.associate = () => {
    app.model.User.hasMany(app.model.Blog, {
      foreignKey: 'userId',
      targetKey: 'Id',
    });
    // UserRelation 加外键
    app.model.User.hasMany(app.model.UserRelation, {
      foreignKey: 'userId',
    });
  };

  return User;

};
